package com.lizemin.bank.config;

import com.lizemin.bank.filter.CsrfFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lzm
 * @date 2025/4/12 10:11
 * @description 配置 Web 相关的 Bean
 */
@Configuration
public class WebConfig {

    /**
     * 注册 RestCsrfPreventionFilter 过滤器
     * @return FilterRegistrationBean 实例
     */
    @Bean
    public FilterRegistrationBean<CsrfFilter> csrfFilter() {
        FilterRegistrationBean<CsrfFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new CsrfFilter());
        // 设置过滤器的 URL 匹配模式，这里表示匹配所有请求
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("loginUrl", "/login");
        registrationBean.addInitParameter("endPoint", "/heartbeat");
        return registrationBean;
    }

}
